<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%@ include file="/WEB-INF/jsp/taglibs-struts2.jsp" %>

<div id="content">
  <div id="breadCrumb"> <a href="#">字典管理</a> / <a href="#">编辑考点考场</a> / </div>
  <h2 id="pageName">编辑考点考场</h2>
  <form id="editFormId" action="college|saveCollegeField.action" method="post">
  <input type="hidden" name="collegeFieldId" value="<c:out value="${fieldtime.id}"/>">
  <div id="messageId" style="display: none; background-color: yellow; width: 200px; "></div>
  <div class="story">
  	<table border="0" cellpadding="3">
  	  <tr><th>考场名称</th><td><input type="text" name="fieldtime.ftName" value="<c:out value="${fieldtime.ftName}"/>"/></td></tr>
  	  <tr><th>考场编码</th><td><input type="text" name="fieldtime.ftCode" value="<c:out value="${fieldtime.ftCode}"/>"/></td></tr>
  	  <tr><th>考点</th><td>
  	    <select name="collegeId" size="1">
  	      <c:forEach var="college" items="${collegeList}">
  	      <option value="<c:out value="${college.id}"/>" <c:if test="${college.id==fieldtime.college.id}">selected</c:if>><c:out value="${college.collegeCode}"/> - <c:out value="${college.collegeName}"/></option>
  	      </c:forEach>
  	    </select>
      </td></tr>
  	  <tr><th>容纳人数</th><td><input type="text" name="fieldtime.ftCount" value="<c:out value="${fieldtime.ftCount}"/>"/></td></tr>
  	  <tr>
  	  	<th>是否有效</th>
  	  	<td><select name="fieldtime.ifValid">
  	  	  <option value="true">是</option>
  	  	  <option value="false" <c:if test="${!fieldtime.ifValid}">selected</c:if>>否</option>
  	  	</select></td>
  	  </tr>
  	  <tr>
  	  	<td colspan="2">
  	  	  <input type="button" name="save" value="保存" onclick="saveCollegeField()"/>
  	  	  <input type="button" name="back" value="返回" onclick="backToList()"/>
  	  	</td>
  	  </tr>
  	</table>
  </div>
  </form>
</div>

<script type="text/javascript">
var msgDiv = $('messageId');

function showSuccMessage(msg) {
msgDiv.innerHTML = msg;
//msgDiv.style.background-color = 'yellow';
msgDiv.style.display = 'block';
}

function showErrMessage(msg) {
msgDiv.innerHTML = msg;
//msgDiv.style.background-color = 'red';
msgDiv.style.display = 'block';
}

function cleanMessage() {
msgDiv.style.display = 'none';
}

function saveCollegeField() {
cleanMessage();
var form = $("editFormId");
var url = form.action;
new Ajax.Request(url, {
  method: "post",
  parameters: Form.serialize(form), 
  onComplete: function (transport) {
    var ret = transport.responseText;
    if(ret != '0') {
      form.collegeFieldId.value = ret;
      showSuccMessage("保存成功!");
    } else {
      showErrMessage("保存失败，可能是名称和编码重复");
    }
  }
});
}

function backToList() {
window.location.href = "college|listCollegeField.action";
}
</script>